# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     auto_run
   Description : 自动下载excel
   Author :       zm.z
   date：          2020/2/5
-------------------------------------------------
   Change Activity:
                   2020/2/5:
-------------------------------------------------
"""
__author__ = 'zm.z'

# coding:utf8
import sys
import xlwt
#import MySQLdb
import pymysql as MySQLdb
import datetime

host = '127.0.0.1'
user = 'a'
pwd = 'a'
db = 'crawl'
sql = 'select DATE(a.crawl_time - INTERVAL 1 DAY) statisicTime,a.* from all_kol_data a limit 10'
sheet_name = '页面1'
out_path = 'one.xls'


conn = MySQLdb.connect(host,user,pwd,db,charset='utf8')
cursor = conn.cursor()
count = cursor.execute(sql)
print(count)

cursor.scroll(0,mode='absolute')
results = cursor.fetchall()
fields = cursor.description
workbook = xlwt.Workbook()
sheet = workbook.add_sheet(sheet_name,cell_overwrite_ok=True)

for field in range(0,len(fields)):
    sheet.write(0,field,fields[field][0])

row = 1
col = 0
for row in range(1,len(results)+1):
    for col in range(0,len(fields)):
        sheet.write(row,col,u'%s'%results[row-1][col])

workbook.save(out_path)
